package com.morningstar.flow.antvX6.node;

import com.alibaba.fastjson2.JSON;
import com.morningstar.flow.antvX6.common.Node;
import com.morningstar.flow.antvX6.common.NodeParser;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import org.flowable.bpmn.model.Process;
import org.flowable.bpmn.model.StartEvent;

import java.util.HashMap;

/**
 * 流程开始节点
 *
 * @author Admin
 */
@Setter
@Getter
public class NodeStart extends Node implements NodeParser {

    public static final String TYPE = "node_start";

    @Override
    public String getNodeType() {
        return TYPE;
    }

    @Override
    public String getNodeName() {
        if (this.getData() != null && StringUtils.isNotBlank(this.getData().getLabel())) {
            return this.getData().getLabel();
        }
        return "开始节点";
    }

    @Override
    public void convertAndAdd(Process process) {
        StartEvent startEvent = new StartEvent();
        startEvent.setId(this.getCName());
        startEvent.setName(this.getData().getLabel());
        process.addFlowElement(startEvent);
    }

    @Override
    public Node parse(HashMap<String, Object> cell) {
        return JSON.parseObject(JSON.toJSONString(cell), NodeStart.class);
    }
}
